import { BasicColumn } from '/@/components/Table/src/types/table';
import { FormSchema } from '/@/components/Form';
import { FormProps } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';

import { getAllDocTypeApi } from '/@/api/demo/flow';
import { Getallpersondto } from '/@/api/demo/system';

const { t } = useI18n();

// 获取所有流程模板数据
export function getFlowComponentColumns(): BasicColumn[] {
  return [
    {
      title: '组件名称',
      dataIndex: 'name',
      fixed: 'left',
      width: 300,
    },
  ];
}

// 获取新增流程模板表单
export function getCreateFlowTemplate(isUpdate): FormSchema[] {
  return [
    {
      field: 'wfid',
      component: 'Input',
      label: '代号',
      required: true,
      dynamicDisabled: () => {
        return isUpdate.value;
      },
      componentProps: {
        placeholder: '请输入代号',
      },
    },
    {
      field: 'wfname',
      component: 'Input',
      label: '名称',
      required: true,
      componentProps: {
        placeholder: '请输入名称',
      },
    },
    {
      field: 'remark',
      component: 'InputTextArea',
      label: '工作说明',
      componentProps: {
        placeholder: '请输入工作说明',
      },
    },
    {
      field: 'actor',
      component: 'ApiSelect',
      label: '负责人',
      defaultValue: 'sa',
      componentProps: {
        disabled: true,
        placeholder: '请输入负责人',
        api: Getallpersondto,
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      field: 'classApplicable',
      component: 'ApiSelect',
      label: '适用对象',
      componentProps: {
        placeholder: '请输入适用对象',
        api: getAllDocTypeApi,
        labelField: 'fileTypeName',
        valueField: 'fileTypeId',
        mode: 'multiple',
      },
    },
    {
      field: 'bzxz',
      component: 'RadioGroup',
      label: '步骤选择',
      componentProps: {
        defaultValue: '1',
        options: [
          {
            value: '0',
            label: '统一设置',
          },
          {
            value: '1',
            label: '流程实例化时设置',
          },
        ],
      },
    },
    {
      field: 'bzxzselected',
      component: 'Checkbox',
      label: ' ',
      colProps: { span: 16 },
      suffix: '允许工作流运行时进行步骤选择',
      itemProps: {
        wrapperCol: { span: 18, offset: 2 },
      },
    },
    {
      field: 'htfs',
      component: 'RadioGroup',
      label: '回退方式',
      componentProps: {
        defaultValue: '1',
        options: [
          {
            value: '0',
            label: '统一设置',
          },
          {
            value: '1',
            label: '流程实例化时设置',
          },
        ],
      },
    },
    {
      field: 'htfsselected',
      component: 'Checkbox',
      label: ' ',
      colProps: { span: 12 },
      suffix: '自由回退',
      itemProps: {
        wrapperCol: { span: 10, offset: 4 },
      },
    },
    {
      field: 'type',
      component: 'Select',
      label: '流程类型',
      componentProps: {
        defaultValue: '通知流程',
        options: [
          {
            value: '通知流程',
            label: '通知流程',
          },
          {
            value: '发布流程',
            label: '发布流程',
          },
          {
            value: '外发流程',
            label: '外发流程',
          },
          {
            value: '变更流程',
            label: '变更流程',
          },
          {
            value: '检出流程',
            label: '检出流程',
          },
          {
            value: '检入流程',
            label: '检入流程',
          },
          {
            value: '借阅流程',
            label: '借阅流程',
          },
          {
            value: '编码申请流程',
            label: '编码申请流程',
          },
        ],
      },
    },
  ];
}

// 获取父级已办/待办流程数据
export function getFlowDoneColumns(): BasicColumn[] {
  return [
    {
      title: '所属审批流程',
      dataIndex: 'workflow',
      fixed: 'left',
      width: 300,
    },
    {
      title: '所属步骤',
      dataIndex: 'step',
      width: 200,
    },
    {
      title: '所属项目',
      dataIndex: 'projname',
      width: 200,
    },
    {
      title: '所属任务',
      dataIndex: 'taskname',
      slots: { customRender: 'taskname' },
      width: 200,
    },
    {
      title: '代号',
      dataIndex: 'dh',
      width: 400,
    },
    {
      title: '回退步骤',
      dataIndex: 'backstep',
      width: 200,
    },
    {
      title: '变化状态',
      dataIndex: 'changestate',
      width: 100,
    },
    {
      title: '建立时间',
      dataIndex: 'createtime',
      slots: { customRender: 'createtime' },
      width: 150,
    },
    {
      title: '计划结束时间',
      dataIndex: 'planendtime',
      slots: { customRender: 'planendtime' },
      width: 150,
    },
    {
      title: '结束时间',
      dataIndex: 'endtime',
      width: 150,
    },
    {
      title: '工作说明',
      dataIndex: 'description',
      width: 150,
    },
    {
      title: '负责人',
      dataIndex: 'actor',
      width: 150,
    },
    {
      title: '是否允许调整对象',
      dataIndex: 'attr',
      width: 150,
    },
    {
      title: '建立人',
      dataIndex: 'creator',
      width: 150,
    },
    {
      title: '备注',
      dataIndex: 'remake',
      width: 150,
    },
    {
      title: '审批权限',
      dataIndex: 'popedom',
      width: 150,
    },
    {
      title: '安全级别',
      dataIndex: 'securityLevel',
      width: 150,
    },
  ];
}

// 获取子级已办/待办流程数据
export function getChildFlowDoneColumns(): BasicColumn[] {
  return [
    {
      title: '代号',
      dataIndex: 'dh',
      width: 200,
    },
    {
      title: '评估',
      dataIndex: 'score',
      width: 100,
    },
    {
      title: '文件名称',
      dataIndex: 'filename',
      width: 100,
    },
    {
      title: '类型',
      dataIndex: 'step',
      width: 100,
    },
  ];
}

// 获取父级已办/待办流程搜索数据
export function getHistorySearch(): Partial<FormProps> {
  return {
    labelWidth: 150,
    colon: false, // 是否显示冒号
    schemas: [
      {
        field: `type`,
        label: `建立/结束`,
        component: 'Select',
        colProps: {
          xl: 12,
          xxl: 8,
        },
        componentProps: {
          placeholder: '请选择建立/结束时间',
          options: [
            {
              value: '0',
              label: '按建立时间',
            },
            {
              value: '1',
              label: '按结束时间',
            },
          ],
        },
      },
      {
        field: `selectStr`,
        label: `关键字`,
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
        componentProps: {
          placeholder: '请输入所属项目、代号',
        },
      },
      {
        field: `planTime`,
        label: `起始-结束时间`,
        component: 'RangePicker',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
    fieldMapToTime: [['planTime', ['startTime', 'endTime'], 'YYYY-MM-DD']],
  };
}

// 获取所有流程模板数据
export function getFlowDetailColumns(): BasicColumn[] {
  return [
    {
      title: '流程步骤',
      dataIndex: 'stepname',
      fixed: 'left',
      width: 300,
    },
    {
      title: '步骤状态',
      dataIndex: 'stepstate',
      width: 200,
    },
    {
      title: '文字批注',
      dataIndex: 'steppz',
      width: 200,
    },
    {
      title: '评估',
      dataIndex: 'projscore',
      width: 200,
    },
    {
      title: '步骤负责人',
      dataIndex: 'stepactor',
      width: 200,
    },
    {
      title: '实际签字人',
      dataIndex: 'stepsign',
      width: 200,
    },
    {
      title: '签字时间',
      dataIndex: 'stepsigntime',
      width: 200,
    },
    {
      title: '备注',
      dataIndex: 'stepnotes',
      width: 200,
    },
  ];
}

// 流程选择表格数据
export function getFlowSelectColumns(): BasicColumn[] {
  return [
    {
      title: '下一步的工作',
      dataIndex: 'step',
      fixed: 'left',
      width: 250,
    },
    {
      title: '负责人代号',
      dataIndex: 'actor',
      width: 150,
    },
    {
      title: '负责人名称',
      dataIndex: 'name',
      width: 150,
    },
  ];
}

// 流程选择表格数据
export function getFlowBackColumns(): BasicColumn[] {
  return [
    {
      title: '下一步的工作',
      dataIndex: 'stepName',
      fixed: 'left',
      width: 250,
    },
    {
      title: '负责人代号',
      dataIndex: 'actor',
      width: 150,
    },
    {
      title: '负责人名称',
      dataIndex: 'actorName',
      width: 150,
    },
  ];
}

// 流程步骤表格
export function getFlowStepColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.step'),
      dataIndex: 'id',
      fixed: 'left',
      width: 300,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.principal'),
      dataIndex: 'name',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.principalCode'),
      dataIndex: 'actor',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.principalHandleWay'),
      dataIndex: 'process',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.name'),
      dataIndex: 'workflow',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.principalName'),
      dataIndex: 'fuZeRen',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.workDescription'),
      dataIndex: 'description',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.overdueMessageReceiverWay'),
      dataIndex: 'argument',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.overdueTime'),
      dataIndex: 'estCostTime',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.overdueMessageReceiver'),
      dataIndex: 'createTime2',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.finishMessageReceiverWay'),
      dataIndex: 'createTime3',
      width: 120,
    },
    {
      title: t('routes.demo.workFlow.startFlow.stepSet.stepTable.finishMessageReceiver'),
      dataIndex: 'createTime4',
      width: 120,
    },
  ];
}

// 流程对象表格
export function getFlowObjColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.workFlow.startFlow.objectSet.name'),
      dataIndex: 'name',
      fixed: 'left',
      width: 200,
    },
    {
      title: t('routes.demo.workFlow.startFlow.objectSet.version'),
      dataIndex: 'version',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.startFlow.objectSet.type'),
      dataIndex: 'type',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.startFlow.objectSet.creator'),
      dataIndex: 'creator',
      width: 110,
    },
  ];
}

// 选择流程表格
export function getSelectionColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.workFlow.selectProcessTable.code'),
      dataIndex: 'id',
      fixed: 'left',
      width: 200,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.name'),
      dataIndex: 'name',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.objectType'),
      dataIndex: 'classApplicable',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.principal'),
      dataIndex: 'actor',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.changeStatus'),
      dataIndex: 'status',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.remark'),
      dataIndex: 'remark',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.overdueTimeSettingWay'),
      dataIndex: 'overTimeProcess',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.overdueTime'),
      dataIndex: 'estCostTime',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.securityLevel'),
      dataIndex: 'securityLevel',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.createTime'),
      dataIndex: 'createTime',
      width: 110,
    },
    {
      title: t('routes.demo.workFlow.selectProcessTable.createUser'),
      dataIndex: 'creator',
      width: 110,
    },
  ];
}

// 调整步骤负责人表格
export function getAdjustColumns(): BasicColumn[] {
  return [
    {
      title: '登录名',
      dataIndex: 'id',
      width: 110,
    },
    {
      title: '名称',
      dataIndex: 'name',
      width: 110,
    },
  ];
}

// 我的流程表格
export function getMyWorkFlowColumns(): BasicColumn[] {
  return [
    {
      title: '名称',
      dataIndex: 'name',
      fixed: 'left',
      width: 300,
    },
    {
      title: '图档代号',
      dataIndex: 'dh',
      width: 300,
    },
    {
      title: '标签',
      dataIndex: 'label',
      width: 100,
    },
    {
      title: '关键字',
      dataIndex: 'keyWord',
      width: 100,
    },
    {
      title: '当前持有者',
      dataIndex: 'currentHolder',
      width: 100,
    },
    {
      title: '类型',
      dataIndex: 'type',
      width: 100,
    },
  ];
}

// 我的流程子表格
export function getChildMyWorkFlowColumns(): BasicColumn[] {
  return [
    {
      title: '表单名称',
      dataIndex: 'formName',
      fixed: 'left',
      width: 200,
    },
    {
      title: '创建人',
      dataIndex: 'creater',
      width: 110,
    },
    {
      title: '生效状态',
      dataIndex: 'status',
      width: 110,
      slots: { customRender: 'status' },
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      width: 110,
      slots: { customRender: 'createTime' },
    },
  ];
}
